package ru.lukyanets.torrent;


import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author slukyanets
 */
public class TorrentInfoMapperTest {

    @Test
    public void testTorrentInfoMapFrom() throws IOException {
        InputStream is = getClass().getClassLoader().getResourceAsStream("test.torrent");

        TorrentInfo torrentInfo = TorrentInfoMapper.from(is);

        Assertions.assertNotNull(torrentInfo);
        //noinspection HttpUrlsUsage
        Assertions.assertEquals("http://tracker.qtorrent.ru:2710/682c4a064caf200102c6d98d3f827da0/announce", torrentInfo.getAnnounceURL());
    }

    @Test
    public void testTorrentInfoMapTo() throws IOException {
        InputStream is = getClass().getClassLoader().getResourceAsStream("test.torrent");
        TorrentInfo torrentInfo = TorrentInfoMapper.from(is);

        ByteArrayOutputStream os = new ByteArrayOutputStream();
        TorrentInfoMapper.to(torrentInfo, os);

        Assertions.assertNotNull(os);
        Assertions.assertEquals(15270, os.size());
    }
}
